Public Class frmToolsOptions
    Public toolCmd() As String

    Private Sub frmToolsOptions_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim i As Integer

        TabControl1.SelectedIndex = 0
        lstToolsOptionsToolsText.Items.Clear()
        txtToolsOptionsToolsCmd.Text = ""

        With options
            With .security
                txtToolsOptionsSecurityDomainAdminUser.Text = .domainAdminUser
                If .domainAdminPassword <> "" Then
                    txtToolsOptionsSecurityDomainAdminPassword.Text = "***"
                End If
            End With
            With .computerDetails
                With .showColumns
                    chkToolsOptionsComputersName.Checked = .computerName
                    chkToolsOptionsComputersIP.Checked = .ip
                    chkToolsOptionsComputersCheckInTime.Checked = .checkinTime
                    chkToolsOptionsComputersManufacturer.Checked = .manufacturer
                    chkToolsOptionsComputersModel.Checked = .model
                    chkToolsOptionsComputersStatus.Checked = .status
                    chkToolsOptionsComputersTemp.Checked = .temp
                    chkToolsOptionsComputersCurrentUser.Checked = .loggedinUser
                    chkToolsOptionsComputersArch.Checked = .arch
                    chkToolsOptionsComputersCPUCount.Checked = .cpuCount
                    chkToolsOptionsComputersProcesses.Checked = .processesCount
                    chkToolsOptionsComputersSerial.Checked = .serial
                    chkToolsOptionsComputersOS.Checked = .operatingSystem
                    chkToolsOptionsComputersRAM.Checked = .ram
                    chkToolsOptionsComputersUptime.Checked = .uptime
                    chkToolsOptionsComputersHD.Checked = .hardDrives
                    chkToolsOptionsComputersCPUs.Checked = .cpuDetails
                End With
                With .tools
                    ReDim toolCmd(.cmd.Length - 1)
                    For i = 0 To .cmd.Length - 1
                        If Not .text(i) Is Nothing Then
                            lstToolsOptionsToolsText.Items.Add(.text(i))
                            toolCmd(i) = .cmd(i)
                        End If
                    Next
                End With
            End With
        End With
    End Sub

    Private Sub btnToolsOptionsOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnToolsOptionsOK.Click
        Dim i As Integer

        With options
            With .computerDetails.tools
                For i = frmMain.cmnGridComputers.Items.Count - 1 To 3 Step -1
                    frmMain.cmnGridComputers.Items.RemoveAt(i)
                Next

                For i = 0 To .cmd.Length - 1
                    If .text(i) <> "" Then
                        frmMain.cmnGridComputers.Items.Add(.text(i), Nothing, AddressOf frmMain.handleCustomComputerTool).Tag = i
                    End If
                Next
            End With

            With .security
                .domainAdminUser = txtToolsOptionsSecurityDomainAdminUser.Text
                If txtToolsOptionsSecurityDomainAdminPassword.Text <> "***" Then
                    .domainAdminPassword = txtToolsOptionsSecurityDomainAdminPassword.Text
                End If
            End With
            With .computerDetails.showColumns
                .computerName = chkToolsOptionsComputersName.Checked
                .ip = chkToolsOptionsComputersIP.Checked
                .checkinTime = chkToolsOptionsComputersCheckInTime.Checked
                .manufacturer = chkToolsOptionsComputersManufacturer.Checked
                .model = chkToolsOptionsComputersModel.Checked
                .status = chkToolsOptionsComputersStatus.Checked
                .temp = chkToolsOptionsComputersTemp.Checked
                .loggedinUser = chkToolsOptionsComputersCurrentUser.Checked
                .arch = chkToolsOptionsComputersArch.Checked
                .cpuCount = chkToolsOptionsComputersCPUCount.Checked
                .processesCount = chkToolsOptionsComputersProcesses.Checked
                .serial = chkToolsOptionsComputersSerial.Checked
                .operatingSystem = chkToolsOptionsComputersOS.Checked
                .ram = chkToolsOptionsComputersRAM.Checked
                .uptime = chkToolsOptionsComputersUptime.Checked
                .hardDrives = chkToolsOptionsComputersHD.Checked
                .cpuDetails = chkToolsOptionsComputersCPUs.Checked

                frmMain.gridComputers.Columns(0).Visible = .computerName
                frmMain.gridComputers.Columns(1).Visible = .ip
                frmMain.gridComputers.Columns(2).Visible = .checkinTime
                frmMain.gridComputers.Columns(3).Visible = .status
                frmMain.gridComputers.Columns(4).Visible = .manufacturer
                frmMain.gridComputers.Columns(5).Visible = .model
                frmMain.gridComputers.Columns(6).Visible = .temp
                frmMain.gridComputers.Columns(7).Visible = .arch
                frmMain.gridComputers.Columns(8).Visible = .cpuCount
                frmMain.gridComputers.Columns(9).Visible = .loggedinUser
                frmMain.gridComputers.Columns(10).Visible = .serial
                frmMain.gridComputers.Columns(11).Visible = .operatingSystem
                frmMain.gridComputers.Columns(12).Visible = .ram
                frmMain.gridComputers.Columns(13).Visible = .uptime
                frmMain.gridComputers.Columns(14).Visible = .hardDrives
                frmMain.gridComputers.Columns(15).Visible = .cpuDetails
                frmMain.gridComputers.Columns(16).Visible = .processesCount
            End With
        End With
        Me.Close()
    End Sub

    Private Sub btnToolsOptionsToolsAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnToolsOptionsToolsAdd.Click
        If frmToolsOptionsNewTool.ShowDialog = Windows.Forms.DialogResult.OK Then
            Dim i As Integer

            i = lstToolsOptionsToolsText.Items.Add(frmToolsOptionsNewTool.txtNewComputerToolText.Text)
            ReDim Preserve options.computerDetails.tools.cmd(i + 1)
            ReDim Preserve options.computerDetails.tools.text(i + 1)
            options.computerDetails.tools.cmd(i) = frmToolsOptionsNewTool.txtNewComputerToolCmd.Text
            options.computerDetails.tools.text(i) = frmToolsOptionsNewTool.txtNewComputerToolText.Text
        End If
    End Sub

    Private Sub lstToolsOptionsToolsText_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstToolsOptionsToolsText.SelectedIndexChanged
        If lstToolsOptionsToolsText.SelectedIndex >= 0 Then
            txtToolsOptionsToolsCmd.Text = options.computerDetails.tools.cmd(lstToolsOptionsToolsText.SelectedIndex)
        End If
    End Sub

    Private Sub btnToolsOptionsToolsDel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnToolsOptionsToolsDel.Click
        Dim i As Integer

        If lstToolsOptionsToolsText.SelectedIndex >= 0 Then
            For i = lstToolsOptionsToolsText.SelectedIndex To lstToolsOptionsToolsText.Items.Count - 2
                options.computerDetails.tools.cmd(i) = options.computerDetails.tools.cmd(i + 1)
                options.computerDetails.tools.text(i) = options.computerDetails.tools.text(i + 1)
            Next

            'clear the last item in the array to avoid it saving it
            'options.computerDetails.tools.cmd(lstToolsOptionsToolsText.Items.Count - 1) = ""
            'options.computerDetails.tools.text(lstToolsOptionsToolsText.Items.Count - 1) = ""

            ReDim Preserve options.computerDetails.tools.cmd(lstToolsOptionsToolsText.Items.Count - 2)
            ReDim Preserve options.computerDetails.tools.text(lstToolsOptionsToolsText.Items.Count - 2)

            i = lstToolsOptionsToolsText.SelectedIndex
            lstToolsOptionsToolsText.Items.RemoveAt(lstToolsOptionsToolsText.SelectedIndex)
            If i <= lstToolsOptionsToolsText.Items.Count - 1 Then
                lstToolsOptionsToolsText.SelectedIndex = i
            Else
                lstToolsOptionsToolsText.SelectedIndex = lstToolsOptionsToolsText.Items.Count - 1
            End If
        End If
    End Sub

    Private Sub btnToolsOptionsToolsRevert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnToolsOptionsToolsRevert.Click
        If lstToolsOptionsToolsText.SelectedIndex >= 0 Then
            txtToolsOptionsToolsCmd.Text = options.computerDetails.tools.cmd(lstToolsOptionsToolsText.SelectedIndex)
        End If
    End Sub

    Private Sub btnToolsOptionsToolsSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnToolsOptionsToolsSave.Click
        If lstToolsOptionsToolsText.SelectedIndex >= 0 Then
            options.computerDetails.tools.cmd(lstToolsOptionsToolsText.SelectedIndex) = txtToolsOptionsToolsCmd.Text
        End If
    End Sub

    Private Sub btnToolsOptionsToolsUp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnToolsOptionsToolsUp.Click
        Dim descTemp As String
        Dim cmdTemp As String

        If lstToolsOptionsToolsText.SelectedIndex > 0 Then
            If lstToolsOptionsToolsText.Items.Count >= 2 Then
                descTemp = options.computerDetails.tools.text(lstToolsOptionsToolsText.SelectedIndex)
                cmdTemp = options.computerDetails.tools.cmd(lstToolsOptionsToolsText.SelectedIndex)
                options.computerDetails.tools.text(lstToolsOptionsToolsText.SelectedIndex) = options.computerDetails.tools.text(lstToolsOptionsToolsText.SelectedIndex - 1)
                options.computerDetails.tools.cmd(lstToolsOptionsToolsText.SelectedIndex) = options.computerDetails.tools.cmd(lstToolsOptionsToolsText.SelectedIndex - 1)
                options.computerDetails.tools.text(lstToolsOptionsToolsText.SelectedIndex - 1) = descTemp
                options.computerDetails.tools.cmd(lstToolsOptionsToolsText.SelectedIndex - 1) = cmdTemp
                lstToolsOptionsToolsText.Items(lstToolsOptionsToolsText.SelectedIndex) = options.computerDetails.tools.text(lstToolsOptionsToolsText.SelectedIndex)
                lstToolsOptionsToolsText.Items(lstToolsOptionsToolsText.SelectedIndex - 1) = options.computerDetails.tools.text(lstToolsOptionsToolsText.SelectedIndex - 1)
                lstToolsOptionsToolsText.SelectedIndex = lstToolsOptionsToolsText.SelectedIndex - 1
            End If
        End If
    End Sub

    Private Sub btnToolsOptionsToolsDown_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnToolsOptionsToolsDown.Click
        Dim descTemp As String
        Dim cmdTemp As String

        If lstToolsOptionsToolsText.SelectedIndex < lstToolsOptionsToolsText.Items.Count - 1 Then
            If lstToolsOptionsToolsText.Items.Count >= 2 Then
                descTemp = options.computerDetails.tools.text(lstToolsOptionsToolsText.SelectedIndex)
                cmdTemp = options.computerDetails.tools.cmd(lstToolsOptionsToolsText.SelectedIndex)
                options.computerDetails.tools.text(lstToolsOptionsToolsText.SelectedIndex) = options.computerDetails.tools.text(lstToolsOptionsToolsText.SelectedIndex + 1)
                options.computerDetails.tools.cmd(lstToolsOptionsToolsText.SelectedIndex) = options.computerDetails.tools.cmd(lstToolsOptionsToolsText.SelectedIndex + 1)
                options.computerDetails.tools.text(lstToolsOptionsToolsText.SelectedIndex + 1) = descTemp
                options.computerDetails.tools.cmd(lstToolsOptionsToolsText.SelectedIndex + 1) = cmdTemp
                lstToolsOptionsToolsText.Items(lstToolsOptionsToolsText.SelectedIndex) = options.computerDetails.tools.text(lstToolsOptionsToolsText.SelectedIndex)
                lstToolsOptionsToolsText.Items(lstToolsOptionsToolsText.SelectedIndex + 1) = options.computerDetails.tools.text(lstToolsOptionsToolsText.SelectedIndex + 1)
                lstToolsOptionsToolsText.SelectedIndex = lstToolsOptionsToolsText.SelectedIndex + 1
            End If
        End If
    End Sub
End Class